package com.qc.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.qc.dao.ActivityTimeDao;
import com.qc.entity.ActivityTimeEntity;

@SuppressWarnings({ "rawtypes", "unchecked" })
@Repository("activityTimeDao")
public class ActivityTimeDaoImpl implements ActivityTimeDao{

	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public int saveActivityTime(ActivityTimeEntity activityTime) {

		String sql = "insert into t_activity_time(start_date,end_date) values(?,?)";
		
		return jdbcTemplate.update(sql,new Object[]{
				activityTime.getStartDate(),activityTime.getEndDate()});
	}

	@Override
	public List<ActivityTimeEntity> listAllActivityTime(int pageNo, int pageSize) {
		
		int beginRow = (pageNo - 1)* pageSize;
		
		String sql = "select * from t_activity_time where 1 = 1";
		
		sql += " order by created_time DESC ";
		sql += " LIMIT "+ String.valueOf(beginRow)+ "," + pageSize;
		
		return jdbcTemplate.query(sql, new BeanPropertyRowMapper(ActivityTimeEntity.class));
	}

}
